package com.red.wine.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.red.wine.R;
import com.red.wine.WineApp;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ParseException;
import android.provider.Settings;
import android.text.TextUtils;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class DialogUtil {
	private static DialogUtil dialogUtil = null;

	static {
		if (dialogUtil == null) {
			dialogUtil = new DialogUtil();
		}
	}
	

	public static ProgressDialog getProgressDialog(Context context,
			String messageString) {
		return getProgressDialog(context, ProgressDialog.STYLE_SPINNER,
				messageString);
	}

	public static Dialog getLoadingDialog(Context context) {
		Dialog dialog = new Dialog(context,
				android.R.style.Theme_Translucent_NoTitleBar);
		dialog.setContentView(R.layout.loading_fullscreen);
		RelativeLayout view = (RelativeLayout) dialog.findViewById(R.id.dialog);
		view.setBackgroundResource(R.color.black);
		view.getBackground().setAlpha(120);
		return dialog;
	}

	public static Dialog getLoadingDialog(Context context, String mess) {
		Dialog dialog = new Dialog(context,
				android.R.style.Theme_Translucent_NoTitleBar);
		dialog.setContentView(R.layout.loading_fullscreen);
		RelativeLayout view = (RelativeLayout) dialog.findViewById(R.id.dialog);
		TextView message = (TextView) dialog.findViewById(R.id.message);
		message.setText(mess);
		view.setBackgroundResource(R.color.black);
		view.getBackground().setAlpha(120);
		return dialog;
	}

	public static ProgressDialog getProgressDialog(Context context, int style,
			String messageString) {
		ProgressDialog dialog = new ProgressDialog(context);
		dialog.setProgressStyle(style);
		dialog.setIndeterminate(true);
		dialog.setCancelable(true);
		dialog.setMessage(messageString);
		return dialog;
	}


	public static AlertDialog getAlertDialog(Activity currentActivity,
			String title, String messageString, String positiveButtonText,
			DialogInterface.OnClickListener positiveButtonListener,
			CharSequence negativeButton,
			DialogInterface.OnClickListener negativeButtonListener) {
		return getAlertDialog(currentActivity, title, messageString,
				positiveButtonText, positiveButtonListener, negativeButton,
				negativeButtonListener, true, true);
	}

	private static AlertDialog getAlertDialog(Activity currentActivity,
			String title, String messageString, String positiveButtonText,
			DialogInterface.OnClickListener positiveButtonListener,
			CharSequence negativeButton,
			DialogInterface.OnClickListener negativeButtonListener,
			boolean isUsePositiveButton, boolean isUseNegativeButton) {
		AlertDialog.Builder builder = new AlertDialog.Builder(currentActivity);
		if (TextUtils.isEmpty(title)) {
			builder.setTitle(R.string.app_name);
		} else {
			builder.setTitle(title);
		}
		if (!TextUtils.isEmpty(messageString)) {
			builder.setMessage(messageString).setCancelable(false);
		}
		if (isUsePositiveButton) {
			builder.setPositiveButton(positiveButtonText,
					positiveButtonListener);
		}
		if (isUseNegativeButton) {
			builder.setNegativeButton(negativeButton, negativeButtonListener);
		}
		return builder.create();
	}

	public static AlertDialog getExitAppDialog(final Activity activity) {
		AlertDialog dialog = new AlertDialog.Builder(activity)
				.setIcon(android.R.drawable.ic_dialog_alert)
				.setTitle(R.string.alert_title)
				.setMessage(R.string.confirm_exit)
				.setPositiveButton(R.string.yes,
						new DialogInterface.OnClickListener() {

							public void onClick(DialogInterface dialog,
									int which) {
								WineApp.getInstance().setExited(true);
							}

						}).setNegativeButton(R.string.no, null).create();
		return dialog;
	}

}
